package com.samoilovich.belarustoday.news;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.samoilovich.belarustoday.Constants;
import com.samoilovich.belarustoday.R;
import com.samoilovich.belarustoday.basefragments.BaseFragmentActivity;
import com.samoilovich.belarustoday.basefragments.NewsContentBaseFragment;
import com.samoilovich.belarustoday.datemodel.CategoryModel;
import com.samoilovich.belarustoday.news.fragments.NewsCategoryFragment;
import com.samoilovich.belarustoday.news.fragments.NewsMainFragment;
import com.samoilovich.belarustoday.tools.Utility;

public class NewsActivity extends BaseFragmentActivity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        mUpdateButtonState = true;
		setContentView(R.layout.main);
        Utility.clearBackStack(this);
        Utility.initImageLoader(this);
		setNewsMainFragment();
	}

	public void setNewsMainFragment() {
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        NewsMainFragment fragment = new NewsMainFragment(NewsActivity.this, Constants.NEWS_MAIN_FRAGMENT_TAG);
		transaction.replace(R.id.frameLayout_content, fragment, Constants.NEWS_MAIN_FRAGMENT_TAG);
		transaction.commit();
	}
	
	public void setNewsCategoryFragment(CategoryModel categoryModel) {
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        NewsCategoryFragment fragment = new NewsCategoryFragment(NewsActivity.this, categoryModel);
		transaction.replace(R.id.frameLayout_content2, fragment, Constants.NEWS_CATEGORY_FRAGMENT_TAG);
		transaction.addToBackStack(null);
		transaction.commit();
	}
	
	public void setNewsContentFragment(long newsId, String categoryName) {
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        NewsContentBaseFragment fragment = new NewsContentBaseFragment(NewsActivity.this, newsId, categoryName);
		transaction.replace(R.id.frameLayout_content3, fragment, Constants.NEWS_CONTENT_FRAGMENT_TAG);
		transaction.addToBackStack(null);
		transaction.commit();
	}

}
